AnnieRoot.ui=AnnieRoot.ui||{};
ui.UserCowsManager=function(){
	var s = this;
	annie.Sprite.call(s);
	/*_a2x_need_start*/s.icon0=null;s.icon1=null;s.icon2=null;s.icon3=null;s.icon4=null;s.icon5=null;s.icon6=null;s.mobileIcon=null;s.num0=null;s.num1=null;/*_a2x_need_end*/
	annie.initRes(s,"ui","UserCowsManager");
	//your code here
	s.addEventListener(annie.Event.ADD_TO_STAGE, function (e) {
		//自适应调整
		s.y = s.stage.viewRect.height + s.stage.viewRect.y - 102 - 20;
	});
	//更新用户牛牛数
	annie.globalDispatcher.addEventListener('updateUserCows', function (e) {
		var num = e.data.num,
			type = e.data.type;
		if (num > 7) {
			s.updateCowsNum(7);
			return;
		}
		s.updateCowsNum(num);
		if (num > 0) {
			num = num - 1;
			s['icon' + num].gotoAndStop(2);
		}
		if (type == 3) {
			//更新手机牛牛Icon
			s.mobileIcon.gotoAndStop(2);
		}
	});
	/*游戏开始*/
	annie.globalDispatcher.addEventListener('resetUserCowsIcon', function (e) {
		for (var i = 0; i < 7; i++) {
			s['icon' + i].gotoAndStop(1);
		}
		s.mobileIcon.gotoAndStop(1);
		s.num0.gotoAndStop(1);
		s.num1.gotoAndStop(1);
	})
};
A2xExtend(ui.UserCowsManager,annie.Sprite);
ui.UserCowsManager.prototype.updateCowsNum = function (num) {
	var s = this,
		numStr = num.toString();
	if (num >= 10) {
		s.num0.gotoAndStop(parseInt(numStr.charAt(1)) + 1);
		s.num1.gotoAndStop(parseInt(numStr.charAt(0)) + 1);
	} else {
		s.num0.gotoAndStop(parseInt(numStr.charAt(0)) + 1);
		s.num1.gotoAndStop(1);
	}
	// trace('num:' + numStr, numStr.charAt(1));
}
